// 定义XsysMenuGrid类的构造函数
var XsysMenuGrid = function (cfg) {

    // 为了在任何情况下可以获得XsysMenuGrid的实例对象
    var me = this;

    // 调用父类构造函数
    XsysMenuGrid.superclass.constructor.call(this, Ext.apply({
        url: 'xsys/menu/list',
        woIdProperty: 'id',
        woNameProperty: 'name',
        woTitle: '菜单列表',
        singleSelect: false,
        woPaging : true,
        woColumns: [
                        {
            header: 'ID',
            dataIndex: 'id',
            hidden: true,
            width: 150
        }
                        ,{
            header: '名称',
            dataIndex: 'name',
            hidden: false,
            width: 150
        }
                ,{
            header: '编号',
            dataIndex: 'no',
            hidden: false,
            width: 150
        }
                ,{
            header: '图标',
            dataIndex: 'icon',
            hidden: false,
            width: 150
        }
                ,{
            header: '面板类',
            dataIndex: 'panelClass',
            hidden: false,
            width: 150
        }
                        , {
            header: '上级菜单ID',
            dataIndex: 'parentId',
            hidden: true,
            width: 150
        }, {
            header: '上级菜单',
            dataIndex: 'parentName',
            hidden: false,
            width: 150
        }
                        ],
        woButtons: [{
            woButtonType: 'wo.list.create', // 创建按钮
            woForm: XsysMenuCreateForm, // 创建表单类
            woGridSelectType: 'singleornone' // 设置列表选择类型：单选或者不选
        }, {
            woButtonType: 'wo.list.delete', // 删除按钮
            woGridSelectType: 'single', // 设置列表选择类型：单选
            woUrl: 'xsys/menu/delete' // 设置删除提交url，key值为selectedIds
        }],
        // 查询字段
        woSearchFields: [{
            items: [{
                name: 'searchContent',
                fieldLabel: '查询内容',
                width: 100
            }]
        }],
        woUpdateForm: XsysMenuUpdateForm // 设置列表双击时，弹出的修改表单类
    }, cfg));
};
// XsysMenuGrid继承Wo.GridPanel
Ext.extend(XsysMenuGrid, Wo.GridPanel, {});

Wo.loadJsByClass('XsysMenuGrid');

// 定义菜单的创建表单，继承Wo.FormPanel
var XsysMenuCreateForm = function (cfg) {
    // 调用父类构造函数
    XsysMenuCreateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: 'xsys/menu/create',
        title: '创建菜单',
        width: 400,
        height: 300,
        items: [
    	                {
            items: [{
                name: 'id',
                fieldLabel: 'ID',
                                allowBlank: true,
                width: 200
            }]
        }
                        , {
            items: [{
                name: 'name',
                fieldLabel: '名称',
                allowBlank: true,
                                width: 200
            }]
        }
                , {
            items: [{
                name: 'no',
                fieldLabel: '编号',
                allowBlank: true,
                                width: 200
            }]
        }
                , {
            items: [{
                name: 'icon',
                fieldLabel: '图标',
                allowBlank: true,
                                width: 200
            }]
        }
                , {
            items: [{
                name: 'panelClass',
                fieldLabel: '面板类',
                allowBlank: true,
                                width: 200
            }]
        }
                        , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: 'parentId', // 上级菜单id
                name: 'parentName', // 上级菜单名称
                fieldLabel: '上级菜单',
                                value: cfg.gridSelectedIds, // 设置列表上选中的菜单ID作为上级菜单ID
                woText: cfg.gridSelectedNames, // 设置列表上选中的菜单名称作为上级菜单名称
                                woPanelClass: 'XsysMenuGrid', // 弹出grid的类
                width: 200
            }]
        }
                        ]
    }, cfg));
};
// 继承
Ext.extend(XsysMenuCreateForm, Wo.FormPanel, {});

// 定义菜单修改表单
var XsysMenuUpdateForm = function (cfg) {
    XsysMenuUpdateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: 'xsys/menu/update',
        title: '修改菜单',
        width: 400,
        height: 300,
        items: [
    	                {
            items: [{
                name: 'id',
                fieldLabel: 'ID',
                width: 200,
                readOnly: true,
                value: cfg.row.get('id')
            }]
        }
    	    	        , {
            items: [{
                name: 'name',
                fieldLabel: '名称',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('name')
            }]
        }
    	        , {
            items: [{
                name: 'no',
                fieldLabel: '编号',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('no')
            }]
        }
    	        , {
            items: [{
                name: 'icon',
                fieldLabel: '图标',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('icon')
            }]
        }
    	        , {
            items: [{
                name: 'panelClass',
                fieldLabel: '面板类',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('panelClass')
            }]
        }
    	    	    	, {
            items: [{
                xtype: 'objectsearch',
                hiddenName: 'parentId',
                name: 'parentName',
                fieldLabel: '上级菜单',
                width: 200,
                value: cfg.row.get('parentId'), // hiddenName对应的值
                woText: cfg.row.get('parentName'), // name对应的值
                woPanelClass: 'XsysMenuGrid', // 弹出grid的类
                width: 200
            }]
        }
    	    	    	]
    }, cfg));
};
Ext.extend(XsysMenuUpdateForm, Wo.FormPanel, {});